﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace hlavny
{
    public partial class indexTryOut : Form
    {
        private cIndHashFile cFile;
        long id = 1;

        Random randGenerator = new Random();
        private string generateString(int length, Boolean big)
        {
            int move;
            if (big == true)
            {
                move = 65;
            }
            else
            {
                move = 97;
            }
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < length; i++)
            {
                builder.Append(Convert.ToChar(Convert.ToInt32(Math.Floor(26 * randGenerator.NextDouble()) + move)));
            }
            return builder.ToString();
        }


        public indexTryOut()
        {
            InitializeComponent();
            cFile = new cIndHashFile("subor.dat", (new modul1.Character("",10)).GetLength(), 5, "hlavny.modul1.Character", 10, 0);
            cFile.iArrayLength = 10;
            
            int found = 0;
            List<string> ozoz = new List<string>();
            Console.WriteLine(DateTime.Now.ToString("mm:ss:ffffff"));
            for (int i = 0; i < 1000; i++)
            {
                string value = generateString(10, false);//rand.Next();
                int address = randGenerator.Next();
                ozoz.Add(value);
                cFile.insertValue(new modul1.Character(value, 10).ToByte(), id++);
                //Console.WriteLine(value + " - " + address);
                /*if (cFile.findKey((new modul1.LongInt(Convert.ToInt64(value))).ToByte()) == -1)
                {
                    found++;
                }*/
                if (i % 1000 == 0)
                {
                    Console.WriteLine(i);
                }
            }
            Console.WriteLine(DateTime.Now.ToString("mm:ss:ffffff"));
            for (int i = 124; i <147 ; i++)
            {
                cFile.deleteValue((new modul1.Character(ozoz[i],10)).ToByte(), i + 1);
                /*if (cFile.findKey((new modul1.LongInt(Convert.ToInt64(ozoz[i]))).ToByte()) == -1)
                {
                    Console.WriteLine(ozoz[i] + " - OK");
                }*/
            }
            found = 0;
            Console.WriteLine("nenajdene " + found);
            for (int i = 0; i < 1000; i++)
            {

                if (cFile.findKey(new modul1.Character(ozoz[i],10).ToByte()) == -1)
                {
                    found++;
                }
            }
            Console.WriteLine("nenajdene " + found);
            int a;
            float b, c;
            modul1.Object o1, o2;
            List<cHistogramColumn> ah;

            cFile.updateValue((new modul1.Character(ozoz[873], 10)).ToByte(),(new modul1.Character(ozoz[873], 10)).ToByte(),  874, 111111);
            cFile.analyze(out b, out c, out o1, out o2, out a, 5, out ah, false);
            cFile.toTextFile("obsah.obs");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            cFile.insertValue(System.BitConverter.GetBytes(Convert.ToInt64(textBox1.Text)), id++);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            long res = cFile.findKey((new modul1.LongInt(Convert.ToInt64(textBox3.Text))).ToByte());
            if (res == -1)
            {
                MessageBox.Show("Nenajdeny");
            }
            else
            {
                MessageBox.Show("Najdeny - | " + res);
            }
        }

    }
}
